<?php
namespace Common\Model;

use Think\Model;

class RouteModel extends Model
{

    public $_validate = array();

    public function addNew()
    {
        $this->_validate = array(
            array('full_url', 'require', '完整url不能为空'),
            array('url', 'require', '实际显示的url不能为空'),
        );
        if (!$this->create()) {
            return false;
        }
        $data = I("post.");
        $this->add($data);
        return true;
    }

    public function getList(){
        $p = I('p',0,'int');
        $limit = C('DEFALUT_PAGE_SIZE');
        $startNum = $p * $limit;
        $count = $this->field("count(*) as count")->find();
        $data = $this->limit($startNum,$limit)->select();
        return array(
            'count' => $count['count'],
            'data'  => $data
        );
    }

    public function edit()
    {
        $this->_validate = array(
            array('full_url', 'require', '完整url不能为空'),
            array('url', 'require', '实际显示的url不能为空'),
        );
        if (!$this->create()) {
            return false;
        }

        $data = I("post.");
        $data['id'] = I('get.id');
        $res = $this->save($data);
        return true;
    }

}
